#! /usr/bin/python3

import json
import os

import requests

if __name__ == '__main__':
    
    fileName = "access_token.txt"
    if os.path.exists(fileName):
        with open(fileName, 'r', encoding='utf-8') as f:
            access_token = f.read().strip()
    else:
        access_token = input("请输入token:\n")
    
    url = f"https://gitee.com/api/v5/user/repos?access_token={access_token}&sort=created&page=1&per_page=100"
    header = {
        "Content-Type": "application/json;charset=UTF-8"
    }
    
    response = requests.get(
        url=url,
        headers=header,
    )
    
    print("Response code:", response.status_code)
    if response.status_code == 200:
        data_list = json.loads(response.text)
        print(len(data_list))
        # print(data_dict)
        for i in range(len(data_list)):
            item = data_list[i]
            print(i + 1, item["created_at"], item["name"], item["html_url"])
    
    else:
        print(response.text)
